<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <ul id="list">
        <li id="li1">列表项1</li>
    </ul>
    <button id="btn">添加新节点</button>
    <button id="btn1">向已有节点前添加新节点</button>
</body>
<script>
    var i = 2;
    var btn = document.getElementById("btn");
    var li1 = document.getElementById("li1");
    btn.onclick = function(){
        var li = document.createElement("li");
        li.innerHTML = "<a href = '#'>列表项"+i+"</a>";
        list.appendChild(li);
        i++;
    }
    btn1.onclick = function(){
        var li = document.createElement("li");
        li.innerHTML = "列表项";
        list.insertBefore(li,li1);
    }
</script>
</html>